/************************************************************************/
/*
 * 
 * All rights reserved.
 *  
 *jdhuang
 * This file is a part of the Intson Foundation Classes library.
 * Author:		 
 * Create on:	2009-3-21
 */
/************************************************************************/
#include <MZFCLIB.h>

#include "UiScrollWinEx.h"

//#include "MzfcDebug.h"

#define MZ_SCROLL_TIMER_INTERVAL	10
#define MZ_SCROLL_ACCEL				-0.3f

UiScrollWinEx::UiScrollWinEx(void)
:	m_bIsEnableDragScroll(true)
,	m_nTopPos(0)
,	m_nLeftPos(0)
,	m_dwTick1(0)
,	m_dwTick2(0)
,	m_nDragMode(UI_DRAGMODE_FREE)
,	m_nChildIndex(-1)
,	m_dwLButtonMoveCount(0)

{
}

UiScrollWinEx::~UiScrollWinEx(void)
{
}
int UiScrollWinEx::OnLButtonDown(UINT fwKeys, int xPos, int yPos)
{
	m_dwLButtonMoveCount = 0;

	m_dwTick2 = GetTickCount();
	SetLButtonDown(true);
//jdhuang
	ScrollStop();
	m_Mouse.Reset();
	m_Mouse.InitPosition(xPos, yPos);
	m_Mouse.SetLButtonDown(xPos,yPos);
//jdhuang 
/*
	for (int n=0; n<GetChildrenCount(); n++)
	{
		UiWin* p = GetChild(n);
		POINT ptChild;
		RECT rtChild;
		ptChild.x = xPos;
		ptChild.y = yPos;
		rtChild = p->GetRect();
		if (p)
		{
			if (p->IsVisible())
			{
				if(PtInRect(&rtChild, ptChild))
				{
					m_nChildIndex = n;
					break;
				}
				else
					m_nChildIndex = -1;
			}
		}
	}
*/
//	if (IsEnableDragScrollbarV() && (GetWidth()-xPos<GetScrollbarMarginV()+MZM_WIDTH_SCROLLBAR+10) )
	if (IsEnableDragScrollbarV())
	{
		double y = yPos;
		double x = xPos;
		double h = GetHeight();
		double w = GetWidth();
//		double dContentH = CalcContentHeight();
		double dContentW = CalcContentWidth();
//		RETAILMSG(1, (TEXT("UiScrollWinEx::OnLButtonDown: x, w, dContentH is :%0.1f, %0.1f, %0.1f\n"), x, w, dContentW));
//		RETAILMSG(1, (TEXT("OnLButtonDown1\n")));

//		if(dContentH>h)
		if(dContentW>w)
		{
			SetIsDragingScrollbarV(true);
//			if(y<0.0f)
			if(x<0.0f)
//				y = 0.0f;
				x = 0.0f;
//			if(y>h)
			if(x>w)
//				y = h;
				x = w;
//			if (h>0.0f)
			if (w>0.0f)
			{
				double dPercentTop = y/h;
				double dPercentLeft = x/w;
				double dTopPos = -dPercentTop*h;
				double dLeftPos = -dPercentLeft*(dContentW-w);
//				RETAILMSG(1, (TEXT("UiScrollWinEx::OnLButtonDown2: y, h, dContentH is :%0.1f, %0.1f, %0.1f\n"), y, h, dContentH));
//				RETAILMSG(1, (TEXT("OnLButtonDown2\n")));
//				SetTopPos(dTopPos);
//jdhuang
//				if(m_nChildIndex == -1)
					SetLeftPos(dLeftPos);
//				else
				{
//					if(dTopPos<h-96)				
//						SetMoveChildPos(dTopPos, dLeftPos);
				}
			}
		}
	}

	return UiWin::OnLButtonDown(fwKeys, xPos, yPos);
}
int UiScrollWinEx::OnLButtonUp(UINT fwKeys, int xPos, int yPos)
{
	m_Mouse.SetLButtonUp(xPos,yPos);

	if (IsEnableDragScrollbarV() && IsDragingScrollbarV())
	{
		SetIsDragingScrollbarV(false);
//		double y = yPos;
//		double h = GetHeight();
//		double dContentH = CalcContentHeight();
		double y = GetWidth();
		double h = xPos;
		double dContentW = CalcContentWidth();
		Invalidate();
//		Update();
//		RETAILMSG(1, (TEXT("UiScrollWinEx::OnLButtonUp: y, h, dContentH is :%0.1f, %0.1f, %0.1f\n"), y, h, dContentW));
//		m_nChildIndex = -1;
//		RETAILMSG(1, (TEXT("OnLButtonUp1\n")));
		return UiWin::OnLButtonUp(fwKeys, xPos, yPos);
	}

	bool bLetMove = false;
//	bool bOuter = (CalcContentHeight()>GetHeight());
	bool bOuter = (CalcContentWidth()>GetWidth());
//	RETAILMSG(1, (TEXT("UiScrollWinEx::OnLButtonUp2: y, h, dContentW is :%d, %d\n"), CalcContentWidth(), GetWidth()));
//	RETAILMSG(1, (TEXT("OnLButtonUp2\n")));
	switch(GetDragMode())
	{
	case UI_DRAGMODE_FREE:
		bLetMove = true;
		break;
	case UI_DRAGMODE_AUTO:
		bLetMove = bOuter;
		break;
	case UI_DRAGMODE_FIXED:
		bLetMove = false;
	}

	if (IsEnableDragScroll())
	{
		if (bLetMove)
		{
//			double d = m_Mouse.GetSpeedY();
			double d = m_Mouse.GetSpeedX();
			ScrollStart(d);
			if (d==0.0f)
			{
				Invalidate();
//				Update();
			}
		}
	}
	else
	{
		ScrollStart(0.0f);
		Invalidate();
//		Update();
	}
//	m_nChildIndex = -1;

	UiWin::OnLButtonUp(fwKeys, xPos, yPos);
	return 0;
}
int UiScrollWinEx::OnMouseMove(UINT fwKeys, int xPos, int yPos)
{
	m_dwLButtonMoveCount ++;
	if(m_dwLButtonMoveCount < 3)
		return 0;

	if (IsEnableDragScrollbarV() && IsDragingScrollbarV())
	{
		double y = yPos;
		double h = GetHeight();
//		double dContentH = CalcContentHeight();

		double x = xPos;
		double w = GetWidth();
		double dContentW = CalcContentWidth();
//		if(dContentH>h)
		if(dContentW>w)
		{
//			if(y<0.0f)
//				y = 0.0f;
			if(x<0.0f)
//				x = 0.0f;
//			if(y>h)
//				y = h;
			if(x>w)
				x = w;
//			if (h>0.0f)
			if (w>0.0f)
			{
				double dPercentTop = y/h;
				double dPercentLeft = x/w;
				double dTopPos = -dPercentTop*(h);
				double dLeftPos = -dPercentLeft*(dContentW-w);
//				SetTopPos(dTopPos);
//				if(m_nChildIndex == -1)
					SetLeftPos(dLeftPos);
//				else
//					if(dTopPos<h-96)				
//						SetMoveChildPos(dTopPos, dLeftPos);
			}
		}
		return UiWin::OnMouseMove(fwKeys, xPos, yPos);
	}

//	int nContentHeight = CalcContentHeight() + GetTopPos();
	int nContentWidth = CalcContentWidth() + GetLeftPos();
	bool bLetMove = false;
//	bool bOuter = GetTopPos()<0 || nContentHeight>GetHeight();
	bool bOuter = GetLeftPos()<0 || nContentWidth>GetWidth();
	switch(GetDragMode())
	{
	case UI_DRAGMODE_FREE:
		bLetMove = true;
		break;
	case UI_DRAGMODE_AUTO:
		bLetMove = bOuter;
		break;
	case UI_DRAGMODE_FIXED:
		bLetMove = false;
	}

	m_Mouse.UpdatePosition(xPos, yPos);
	if(IsLButtonDown() && bLetMove)
	{
		SetIsScrolling(true);
		m_dwTick1 = m_dwTick2;
		m_dwTick2 = GetTickCount();

		//m_Mouse.SetLButtonDown(xPos,yPos);

		int nNewTopPos = GetTopPos()+m_Mouse.GetMovedY();
		int nNewLeftPos = GetLeftPos()+m_Mouse.GetMovedX();
//		SetTopPos(nNewTopPos);
//		if(m_nChildIndex == -1)
			SetLeftPos(nNewLeftPos);
//		else
//			if(nNewTopPos<GetHeight()-96)				
//				SetMoveChildPos(nNewTopPos, nNewLeftPos);
	}
	SetMouseMoved(true);
	return 0;
}
int UiScrollWinEx::OnTimer(UINT_PTR nIDEvent)
{
	if(nIDEvent==MZ_TIMER_ID_WIN_SCROLL+GetID())
	{
		m_Anim.Tick();
		int nNewTopPos = m_Anim.GetSd();
		int nNewLeftPos = m_Anim.GetSd();
//		SetTopPos(nNewTopPos);
//		if(m_nChildIndex == -1)
			SetLeftPos(nNewLeftPos);
//		else
//			if(nNewTopPos<GetHeight()-96)				
//				SetMoveChildPos(nNewTopPos, nNewLeftPos);

		if(m_Anim.GetCurMode()==EAM_NONE)
		{
//jdhuang
//			m_nChildIndex = -1;
			ScrollStop();
			ReleaseCapture();
		}
	}
	return 0;
}

void UiScrollWinEx::EnableDragScroll( bool bEnable )
{
	m_bIsEnableDragScroll = bEnable;
}

bool UiScrollWinEx::IsEnableDragScroll()
{
	return m_bIsEnableDragScroll;
}
int UiScrollWinEx::CalcContentHeight()
{
	int nTop = 0;
	int nBottom = 0;
	int c = 0;
	for (int n=0; n<GetChildrenCount(); n++)
	{
		UiWin* p = GetChild(n);
		if (p)
		{
			if (p->IsVisible())
			{
				int t = p->GetPosY();
				int b = t + p->GetHeight();
				if (c==0)
				{
					nTop = t;
					nBottom = b;
				}
				else
				{
					if (t<nTop)
						nTop = t;
					if (b>nBottom)
						nBottom = b;
				}
				c++;
			}
		}
	}
	int nTopPos = GetTopPos();
	if(nTop>nTopPos)
		nTop = nTopPos;
	return nBottom-nTop;
}
int UiScrollWinEx::CalcContentWidth()
{
//	return GetWidth();
//	int nTop = 0;
//	int nBottom = 0;
	int nLeft = 0;
	int nRight = 0;
	int c = 0;
	for (int n=0; n<GetChildrenCount(); n++)
	{
		UiWin* p = GetChild(n);
		if (p)
		{
			if (p->IsVisible())
			{
//				int t = p->GetPosY();
				int t = p->GetPosX();
//				int b = t + p->GetHeight();
				int b = t + p->GetWidth();
				if (c==0)
				{
//					nTop = t;
//					nBottom = b;
					nLeft = t;
					nRight = b;
				}
				else
				{
//					if (t<nTop)
//						nTop = t;
//					if (b>nBottom)
//						nBottom = b;
					if (t<nLeft)
						nLeft = t;
					if (b>nRight)
						nRight = b;
				}
				c++;
			}
		}
	}
//	int nTopPos = GetTopPos();
//	if(nTop>nTopPos)
//		nTop = nTopPos;
//	return nBottom-nTop;
	int nLeftPos = GetTopPos();
	if(nLeft>nLeftPos)
		nLeft = nLeftPos;
	return nRight-nLeft;
}
int UiScrollWinEx::CalcContentTopPosV()
{
//	return m_nTopPos;
	return 0;
}
int UiScrollWinEx::CalcContentTopPosH()
{
//	return 0;
	return m_nLeftPos;
}

void UiScrollWinEx::ScrollStop()
{
	KillTimer(GetManager()->GetParentWnd(), MZ_TIMER_ID_WIN_SCROLL+GetID());
	SetIsScrolling(false);
	Invalidate();
//	Update();
	UiWin::ScrollStop();
}

void UiScrollWinEx::ScrollStart( double fScrollSpeed)
{
	//bool bMove = m_dwTick2-m_dwTick1<-200 && m_dwTick2-m_dwTick1>200;
	bool bMove = false;


	if(bMove || fScrollSpeed==0)
	{
//		m_Anim.Init(GetHeight(), CalcContentHeight(), CalcContentTopPosV(), MZ_SCROLL_ACCEL, 0, 1);
		m_Anim.Init(GetWidth(), CalcContentWidth(), CalcContentTopPosH(), MZ_SCROLL_ACCEL, 0, 1);
		if (m_Anim.GetCurMode()==MZ_ANIMTYPE_NONE)
		{
#if 0
			SetIsScrolling(false);
#else
			SetIsScrolling(true);
			UINT i = SetTimer(GetManager()->GetParentWnd(), MZ_TIMER_ID_WIN_SCROLL+GetID(), MZ_SCROLL_TIMER_INTERVAL, 0);
			PostMessage(MZ_WM_UI_SCROLL_START, GetID(), 0);
#endif
			return;
		}
		else
		{
			SetIsScrolling(true);
			UINT i = SetTimer(GetManager()->GetParentWnd(), MZ_TIMER_ID_WIN_SCROLL+GetID(), MZ_SCROLL_TIMER_INTERVAL, 0);
			PostMessage(MZ_WM_UI_SCROLL_START, GetID(), 0);
			return;
		}
	}
	if(fScrollSpeed!=0)
	{
//		m_Anim.Init(GetHeight(), CalcContentHeight(), CalcContentTopPosV(), MZ_SCROLL_ACCEL, fScrollSpeed*1.0f, 1);
		m_Anim.Init(GetWidth(), CalcContentWidth(), CalcContentTopPosH(), MZ_SCROLL_ACCEL, fScrollSpeed*1.0f, 1);
		UINT i = SetTimer(GetManager()->GetParentWnd(), MZ_TIMER_ID_WIN_SCROLL+GetID(), MZ_SCROLL_TIMER_INTERVAL, 0);
		PostMessage(MZ_WM_UI_SCROLL_START, GetID(), 0);
		return;
	}
}

bool UiScrollWinEx::IsScrollable()
{
	return true;
}

int UiScrollWinEx::GetTopPos()
{
	return m_nTopPos;
}

void UiScrollWinEx::SetTopPos( int nTopPos )
{
//	DWORD dwTick1 = GetTickCount();

	int nPrev = GetTopPos();
	if(nTopPos==nPrev)
		return;

	int nDelta = nTopPos-m_nTopPos;
	int h = GetHeight();
	if (!IsEnableScrollOptimize() || nDelta>=h || nDelta<=-h)
	{
		m_nTopPos = nTopPos;
		MoveChildren(0, nDelta);
		Invalidate();
//		Update();
//		RETAILMSG(1, (TEXT("UiScrollWinEx::SetTopPos: Move(%d), TimeCost(%u)\n"), nDelta, GetTickCount()-dwTick1));
		return;
	}

	//////////////////////////////////////////////////////////////////////////
	m_nTopPos = nTopPos;
	MoveChildren(0, nDelta);

	RECT rcDst = GetClientRect();
	int x = 0;
	int y = 0;
	CalcRelativePos(this, x, y, true);
	OffsetRect(&rcDst, x, y);
	RECT rcScroll = {rcDst.left+GetEllipsis_Left(), rcDst.top+GetEllipsis_Top(),
		rcDst.right-GetEllipsis_Right(), rcDst.bottom-GetEllipsis_Bottom()};
	RECT rcClipSrc = rcScroll;
	RECT rcClipDst = rcScroll;
	if (nDelta<0)
	{
		rcClipSrc.top -= nDelta;
		rcClipDst.bottom += nDelta;
	}
	else
	{
		rcClipSrc.bottom -= nDelta;
		rcClipDst.top += nDelta;
	}

	WinManager *pMan = GetManager();
	if (pMan)
	{
		HWND hWnd = pMan->GetParentWnd();
		CMzWnd* pWnd = CMzWnd::FromHandle(hWnd);
		if (pWnd)
		{
			pWnd->ScrollWindow_So(&rcDst,&rcScroll,&rcClipSrc,&rcClipDst);
		}
	}
//	RETAILMSG(1, (TEXT("UiScrollWinEx::SetTopPos (scroll optimized): Move(%d), TimeCost(%u)\n"), nDelta, GetTickCount()-dwTick1));
	//////////////////////////////////////////////////////////////////////////



	//if(abs(nTopPos - nPrev)<GetHeight())
	//{
	//	//copy dc of the window
	//	int nDelta = nTopPos - nPrev;
	//	int x = 0;
	//	int y = 0;
	//	CalcRelativePos(this, x,y,true);
	//	RECT rcWin = GetClientRect();
	//	OffsetRect(&rcWin, x, y);
	//	RECT rcScroll = rcWin;
	//	RECT rcClip = rcWin;
	//	RECT rcUpdate = rcWin;
	//	if (nDelta>0)
	//	{
	//		rcUpdate.bottom = rcUpdate.top+nDelta;
	//	}
	//	else
	//	{
	//		rcUpdate.top = rcUpdate.bottom+nDelta;
	//	}
	//	ScrollWindowEx(GetManager()->GetParentWnd(), 0, nDelta, &rcScroll, &rcClip, 0,0,0);
	//	InvalidateRect(GetManager()->GetParentWnd(), &rcUpdate, FALSE);
	//	Update();
	//	return;
	//}

	//Invalidate();
	//Update();
}
//jdhuang
void UiScrollWinEx::SetMoveChildPos(int nTopPos, int nLeftPos)
{
//	DWORD dwTick1 = GetTickCount();

	int nPrevTop = GetTopPos();
	int nPrevLeft = GetLeftPos();
	if((nTopPos==nPrevTop) && (nLeftPos==nPrevLeft))
		return;
	
	int nDeltaTop = nTopPos-m_nTopPos;
	int nDeltaLeft = nLeftPos-m_nLeftPos;
	int h = GetHeight();
	int w = GetWidth();
//	if (!IsEnableScrollOptimize() || nDelta>=h || nDelta<=-h)
	if (!IsEnableScrollOptimize() || nDeltaLeft>=w || nDeltaLeft<=-w || nDeltaTop>=h || nDeltaTop<=-h)
	{
//		m_nTopPos = nTopPos;
//		m_nLeftPos = nLeftPos;
//		MoveChildren(0, nDelta);
//		MoveChildren(nDelta, 0);
		UiWin* p = GetChild(m_nChildIndex);
		if (p)
		{
			if (p->IsVisible())
			{
				p->Move(nDeltaLeft, nDeltaTop);
				Invalidate();
//				Update();
			}
		}
//		RETAILMSG(1, (TEXT("UiScrollWinEx::SetLeftPos: Move(%d), TimeCost(%u)\n"), nDelta, GetTickCount()-dwTick1));
		return;
	}
}
void UiScrollWinEx::SetLeftPos(int nLeftPos)
{
//	DWORD dwTick1 = GetTickCount();

//	int nPrev = GetTopPos();
	int nPrev = GetLeftPos();
//	if(nTopPos==nPrev)
	if(nLeftPos==nPrev)
		return;

//	int nDelta = nTopPos-m_nTopPos;
	int nDelta = nLeftPos-m_nLeftPos;
//	int h = GetHeight();
	int w = GetWidth();
//	if (!IsEnableScrollOptimize() || nDelta>=h || nDelta<=-h)
	if (!IsEnableScrollOptimize() || nDelta>=w || nDelta<=-w)
	{
//		m_nTopPos = nTopPos;
		m_nLeftPos = nLeftPos;
//		MoveChildren(0, nDelta);
		MoveChildren(nDelta, 0);
		Invalidate();
//		Update();
//		RETAILMSG(1, (TEXT("UiScrollWinEx::SetLeftPos: Move(%d), TimeCost(%u)\n"), nDelta, GetTickCount()-dwTick1));
		return;
	}

	//////////////////////////////////////////////////////////////////////////
//	m_nTopPos = nTopPos;
	m_nLeftPos = nLeftPos;
	MoveChildren(0, nDelta);

	RECT rcDst = GetClientRect();
	int x = 0;
	int y = 0;
	CalcRelativePos(this, x, y, true);
	OffsetRect(&rcDst, x, y);
	RECT rcScroll = {rcDst.left+GetEllipsis_Left(), rcDst.top+GetEllipsis_Top(),
		rcDst.right-GetEllipsis_Right(), rcDst.bottom-GetEllipsis_Bottom()};
	RECT rcClipSrc = rcScroll;
	RECT rcClipDst = rcScroll;
	if (nDelta<0)
	{
//		rcClipSrc.top -= nDelta;
//		rcClipDst.bottom += nDelta;
		rcClipSrc.left -= nDelta;
		rcClipDst.right += nDelta;
	}
	else
	{
//		rcClipSrc.bottom -= nDelta;
//		rcClipDst.top += nDelta;
		rcClipSrc.right -= nDelta;
		rcClipDst.left += nDelta;
	}

	WinManager *pMan = GetManager();
	if (pMan)
	{
		HWND hWnd = pMan->GetParentWnd();
		CMzWnd* pWnd = CMzWnd::FromHandle(hWnd);
		if (pWnd)
		{
			pWnd->ScrollWindow_So(&rcDst,&rcScroll,&rcClipSrc,&rcClipDst);
		}
	}
//	RETAILMSG(1, (TEXT("UiScrollWinEx::SetTopPos (scroll optimized): Move(%d), TimeCost(%u)\n"), nDelta, GetTickCount()-dwTick1));
}
//jdhuang
void UiScrollWinEx::SetLeftPosToRight()
{
//	if (CalcContentHeight() < GetHeight())
	if (CalcContentWidth() < GetWidth())
	{
		return;
	}

//	SetTopPos(GetHeight()- CalcContentHeight());
	SetLeftPos(GetWidth()- CalcContentWidth());
}
//jdhuang
int UiScrollWinEx::GetLeftPos()
{
//	return m_nTopPos;
	return m_nLeftPos;

}
void UiScrollWinEx::Scroll( int nOffset )
{
//	m_nTopPos += nOffset;
//	MoveChildren(0, nOffset);
	m_nLeftPos += nOffset;
	MoveChildren(nOffset, 0);
}
void UiScrollWinEx::ScrollTo(int nScrollToType/* =UI_SCROLLTO_TOP */, int nDstTopPos/* =0 */, bool bAnimate/* =true */)
{
	double dDstTopPos = 0;
	double dDstLeftPos = 0;
	switch(nScrollToType)
	{
	case UI_SCROLLTO_TOP:
		{
			dDstTopPos = 0;
			break;
		}
		break;
	case UI_SCROLLTO_BOTTOM:
		{
			int nContentHeight = CalcContentHeight();
			int nHeight = GetHeight();
			if (nContentHeight>=nHeight)
			{
				dDstTopPos = nHeight-nContentHeight;
				break;
			}
			else
			{
				dDstTopPos = 0;
				break;
			}
		}
		break;
	case UI_SCROLLTO_LEFT:
		{
			dDstTopPos = 0;
			break;
		}
		break;
	case UI_SCROLLTO_RIGHT:
		{
//			int nContentHeight = CalcContentHeight();
			int nContentWidth = CalcContentWidth();
//			int nHeight = GetHeight();
			int nWidth = GetWidth();
//			if (nContentHeight>=nHeight)
			if (nContentWidth>=nWidth)
			{
//				dDstTopPos = nHeight-nContentHeight;
				dDstTopPos = nWidth-nContentWidth;
				break;
			}
			else
			{
				dDstTopPos = 0;
				break;
			}
		}
		break;
	case UI_SCROLLTO_POS:
		{
			int nContentHeight = CalcContentHeight();
			int nHeight = GetHeight();
			int nTopPos = GetTopPos();
			if (nDstTopPos>=0)
			{
				dDstTopPos = 0;
				break;
			}
			else
			{
				if (nContentHeight<=nHeight)
				{
					dDstTopPos = 0;
					break;
				}
				else
				{
					if (nDstTopPos<nHeight-nContentHeight)
					{
						dDstTopPos = nHeight-nContentHeight;
						break;
					}
					else
					{
						dDstTopPos = nDstTopPos;
						break;
					}
				}
			}
		}
		break;
	}

	SetIsScrolling(true);
	if (bAnimate)
	{
//		double dPos = GetTopPos();
		double dPos = GetLeftPos();
		while (dPos!=dDstTopPos)
		{
			double dDelta = (dPos-dDstTopPos)/1.5f;
			if (abs(dDelta)<1.0f)
			{
				dDelta = (dDelta<0.0f)?-1:1;
			}
			if (dDelta==0.0f)
			{
				break;
			}
			dPos -= dDelta;
//			SetTopPos(dPos);
			SetLeftPos(dPos);
//			dPos = GetTopPos();
			dPos = GetLeftPos();
		}
	}
	else
	{
//		SetTopPos(dDstTopPos);
		SetLeftPos(dDstLeftPos);
	}
	SetIsScrolling(false);
	Invalidate();
//	Update();
}

void UiScrollWinEx::SetTopPosToBottom()
{
	if (CalcContentHeight() < GetHeight())
	{
		return;
	}

	SetTopPos(GetHeight()- CalcContentHeight());
}

void UiScrollWinEx::SetDragMode( int nDragMode )
{
	m_nDragMode = nDragMode;
}

int UiScrollWinEx::GetDragMode()
{
	return m_nDragMode;
}